package com.jia.jwt.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;

public class JwtUtil {

    public static String SIGN_KET = "SKDJSODLAKJasdf55";

    public static String createJwt() {
        long current = System.currentTimeMillis();
        long exp = current + 1000 *60 *2;
        JwtBuilder jwtBuilder = Jwts.builder()
                .claim("username","jia")
                .setExpiration(new Date(exp))
                .signWith(SignatureAlgorithm.HS256, SIGN_KET);

        String token = jwtBuilder.compact();
        return token;
    }

    public static Claims parseJwt(String token) {
        Claims body = Jwts.parser()
                .setSigningKey(SIGN_KET)
                .parseClaimsJws(token)
                .getBody();
        return body;
    }



}
